<?php

/**
 * passport actions.
 *
 * @package    tmdb
 * @subpackage passport
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */
class passportActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
    $this->passport_list = Doctrine::getTable('Passport')
      ->createQuery('a')
 			->where('a.person_id = ?',$request->getParameter('px_id'))
      ->execute();
	$this->px_id = ($request->getParameter('px_id'));
  }

  public function executeShow(sfWebRequest $request)
  {
    $this->passport = Doctrine::getTable('Passport')->find(array($request->getParameter('id')));
		$this->px_id = ($this->passport->getperson_id());
    $this->forward404Unless($this->passport);
  }

  public function executeNew(sfWebRequest $request)
  {	
		$passport = new Passport();
		$passport->setperson_id($request->getParameter('px_id'));
		$this->px_id = ($request->getParameter('px_id'));
    $this->form = new PassportForm($passport);
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod('post'));
		$px_id = ($request->getParameter('px_id'));
    $this->form = new PassportForm();

    $this->processForm($request, $this->form, $px_id);
		$this->px_id = ($request->getParameter('px_id'));
    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($passport = Doctrine::getTable('Passport')->find(array($request->getParameter('id'))), sprintf('Object passport does not exist (%s).', array($request->getParameter('id'))));
		$this->px_id = ($passport->getperson_id());
    $this->form = new PassportForm($passport);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod('post') || $request->isMethod('put'));
    $this->forward404Unless($passport = Doctrine::getTable('Passport')->find(array($request->getParameter('id'))), sprintf('Object passport does not exist (%s).', array($request->getParameter('id'))));
    $this->form = new PassportForm($passport);
		$px_id = ($request->getParameter('px_id'));
    $this->processForm($request, $this->form, $px_id);
		$this->px_id = ($request->getParameter('px_id'));
    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    $this->forward404Unless($passport = Doctrine::getTable('Passport')->find(array($request->getParameter('id'))), sprintf('Object passport does not exist (%s).', array($request->getParameter('id'))));
    $passport->delete();
		$this->px_id = ($passport->getperson_id());
    $this->redirect('passport/index?px_id='.$px_id);
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()));
    if ($form->isValid())
    {
      $passport = $form->save();
			$px_id = $passport->getperson_id();
			$this->px_id = $px_id;
      $this->redirect('passport/index?px_id='.$px_id);
    }
  }
}
